Source Code Viewer - Example 4 - FindGameListByFamilyAction

package name.matthewgreet.example4.action;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.opensymphony.xwork2.ActionSupport;

import name.matthewgreet.example4.common.AbstractFormDrivenActionSupport;
import name.matthewgreet.example4.common.ListCache;
import name.matthewgreet.example4.common.ListFinder;
import name.matthewgreet.example4.common.NA;
import name.matthewgreet.example4.dto.GameDTO;
import name.matthewgreet.example4.form.GameFamilyForm;
import name.matthewgreet.example4.model.GameTable;
import name.matthewgreet.example4.model.GameTable.GameOption;
import name.matthewgreet.example4.util.GameCompositeCache;
import name.matthewgreet.example4.model.Model;

/**
 * Finds board games by overall ranking or ranking of a category.  
 */
@InterceptorRef("FormDrivenStack")
@Results({
	@Result(name=ActionSupport.INPUT, type="redirectAction", params = {"namespace", "/", "actionName", "ViewGameList"}),
	@Result(name=ActionSupport.SUCCESS, type="redirectAction", params = {"namespace", "/", "actionName", "ViewGameList"})
})
public class FindGameListByFamilyAction extends AbstractFormDrivenActionSupport<GameFamilyForm> {
	public static class GameListFinderByFamily implements ListFinder<NA,GameDTO> {
		private static final long serialVersionUID = 6409312894523453002L;
		
		private String family;
		
		public GameListFinderByFamily(String family) {
			this.family = family;
		}

		@Override
		public List<GameDTO> getList(NA selectedMaster) throws Exception {
			GameTable gameTable;
			
			gameTable = Model.getInstance().getGameTable();
			return gameTable.findByFamily(family, GameOption.DESIGNERS);
		}
		
		public String getFamily() {
			return family;
		}

	}
	
	
	private static final long serialVersionUID = -7979376337555804889L;
	
    @Action("/FindGameListByFamily")
    @Override
    public String execute() throws Exception {
    	GameFamilyForm form;
    	ListCache<NA,Integer,GameDTO> listCache;
    	HttpSession session;
    	
    	form = getModel();
    	
    	session = getRequest().getSession();
    	listCache = GameCompositeCache.getInstance(session).getMasterListCache();
    	listCache.setListFinder(new GameListFinderByFamily(form.getFamily()));
		
		return SUCCESS;
    }

	@Override
	protected GameFamilyForm makeForm() {
		return new GameFamilyForm();
	}

}